<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      th:replace="layout/base :: layout(~{::title}, ~{::main})">
<head>
    <title>注册 - 博客系统</title>
</head>
<body>
    <main>
        <div class="row justify-content-center">
            <div class="col-md-6 col-lg-4">
                <div class="card">
                    <div class="card-body">
                        <h3 class="card-title text-center mb-4">用户注册</h3>
                        <form th:action="@{/api/auth/register-form}" method="post">
                            <div class="mb-3">
                                <label for="username" class="form-label">用户名</label>
                                <input type="text" class="form-control" id="username" name="username"
                                       th:value="${userDto?.username}" required autofocus
                                       pattern=".{4,50}" title="用户名长度必须在4-50个字符之间">
                            </div>
                            <div class="mb-3">
                                <label for="email" class="form-label">邮箱</label>
                                <input type="email" class="form-control" id="email" name="email"
                                       th:value="${userDto?.email}" required>
                            </div>
                            <div class="mb-3">
                                <label for="password" class="form-label">密码</label>
                                <input type="password" class="form-control" id="password" name="password"
                                       required pattern=".{6,100}" title="密码长度必须在6-100个字符之间">
                            </div>
                            <div class="mb-3">
                                <label for="confirmPassword" class="form-label">确认密码</label>
                                <input type="password" class="form-control" id="confirmPassword"
                                       required oninput="checkPasswordMatch();">
                            </div>
                            <div class="d-grid gap-2">
                                <button type="submit" class="btn btn-primary" id="submitBtn">注册</button>
                                <a href="/login" class="btn btn-link">已有账号？立即登录</a>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <script>
            function checkPasswordMatch() {
                var password = document.getElementById('password');
                var confirmPassword = document.getElementById('confirmPassword');
                var submitBtn = document.getElementById('submitBtn');
                
                if (password.value != confirmPassword.value) {
                    confirmPassword.setCustomValidity('两次输入的密码不匹配');
                    submitBtn.disabled = true;
                } else {
                    confirmPassword.setCustomValidity('');
                    submitBtn.disabled = false;
                }
            }
        </script>
    </main>
</body>
</html> 